<?php

namespace App;

use App\Http\Controllers\Api\PaymentController;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\PrescriptionInfo
 *
 * @property int $id
 * @property int $enterprise_id 商家id
 * @property int $user_drug_id 用药人id
 * @property int $order_id 订单id
 * @property int $has_prescription 是否有处方 0：否 1：是
 * @property string|null $perscriptionNumber 处方单号
 * @property int|null $perscriptionStatus 处方状态(0-未提交审核 1-等待医生接诊 3-医生已接诊 5-医生已完成开方 99-医生拒绝开方)
 * @property string|null $diagnoseDescription 患者主述
 * @property string|null $diagnosticLevel 诊断级别(1-普通患病并已确诊2-慢性病并确诊 3-尚未确诊)
 * @property string|null $drugUsage 既往用药情况(1-药物用完需继续购买完成疗程 2-医生建议使用此药)
 * @property string|null $checkDoctorName 药店审核医师名称
 * @property string|null $reviewDoctorName 药店复核医师名称
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\PrescriptionInfo onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereCheckDoctorName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereDiagnoseDescription($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereDiagnosticLevel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereDrugUsage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereEnterpriseId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereHasPrescription($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo wherePerscriptionNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo wherePerscriptionStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereReviewDoctorName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereUserDrugId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\PrescriptionInfo withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\PrescriptionInfo withoutTrashed()
 * @mixin \Eloquent
 * @property string|null $refuse_reason 拒绝开方原因
 * @method static \Illuminate\Database\Eloquent\Builder|\App\PrescriptionInfo whereRefuseReason($value)
 */
class PrescriptionInfo extends Model
{
    //
    use SoftDeletes;

    public static function getPrescriptionInfo($id){
        if(empty($id))
            return null;

        $data = self::whereId($id)->first();
        if($data){
            $data->user_drug_Info = UserDrug::getUserDrugInfo($data->user_drug_id);

            $data->status = '';
            if($data->perscriptionStatus == 0)
                $data->status = '未提交处方审核';
            elseif($data->perscriptionStatus == 1)
                $data->status = '等待医生接诊';
            elseif($data->perscriptionStatus == 3)
                $data->status = '医生已接诊';
            elseif($data->perscriptionStatus == 5)
                $data->status = '医生已完成开方';
            elseif($data->perscriptionStatus == 99)
                $data->status = '医生拒绝开方';

            $data->prescription_img_list = PrescriptionInfoImgs::getPrescriptionInfoImgList($data->id);

            $data->prescription_disease_list = PrescriptionDisease::getPrescriptionDiseaseList($data->id);

            if($data->diagnosticLevel == 1)
                $data->diagnostic_level_name = '普通患病并已确诊';
            elseif($data->diagnosticLevel == 2)
                $data->diagnostic_level_name = '慢性病并确诊';
            elseif($data->diagnosticLevel == 3)
                $data->diagnostic_level_name = '尚未确诊';
            else
                $data->diagnostic_level_name = $data->diagnosticLevel;

            if($data->drugUsage == 1)
                $data->drug_usage_name = '药物用完需继续购买完成疗程';
            elseif($data->drugUsage == 2)
                $data->drug_usage_name = '医生建议使用此药';
            else
                $data->drug_usage_name = $data->drugUsage;

            $data->check_doctor_name = '张医师';
            $data->review_doctor_name = '张医师';
            $data->arrange_doctor_name = '李医师';
            $doctorList = PaymentController::getDoctorList();
            if(count($doctorList)  == 3){
                $data->check_doctor_name = $doctorList[0];
                $data->review_doctor_name = $doctorList[1];
                $data->arrange_doctor_name = $doctorList[2];
            }elseif(count($doctorList)  == 2){
                $data->check_doctor_name = $doctorList[0];
                $data->review_doctor_name = $doctorList[0];
                $data->arrange_doctor_name = $doctorList[1];
            }elseif(count($doctorList)  == 1){
                $data->check_doctor_name = $doctorList[0];
                $data->review_doctor_name = $doctorList[0];
            }

        }

        return $data;
    }
}
